<?
require_once('view/htmlTag.class.php');
class view{

	const PATH_TO_STYLE = '/public/style/';
	const PATH_TO_SCRIPT = '/public/js/';
	const VIEW_DIR = "./application/views/";
	private $vars;
	private $tpl;
	
	
	
	public function __construct(){
		$this -> vars = array();
		$this -> vars['styles'] = array();
		$this -> vars['scripts'] = array();
	}
	
	
	public function setTpl($iTpl){
	
		$this -> tpl = $iTpl;
	
	}
	
	
	public function render(){
	
		if(file_exists(self::VIEW_DIR.$this -> tpl)){
				
			require_once(self::VIEW_DIR.$this -> tpl);
		
		}else{
		
			throw new Exception("Template does'nt exist");
		
		}
	
	}
	
	public function addStyle($style){
		
		$tag = new view_htmlTag('link');
		$tag -> setAttribute('href', $style);
		$tag -> setAttribute('rel', 'stylesheet');
		$tag -> setAttribute('type', 'text/css');
		$tag -> setToShortTag();
		
		$this -> vars['styles'][] = $tag;
	
	}
	
	
	public function addScript($script){
		
		$tag = new view_htmlTag('script');
		$tag -> setAttribute('src', $script);
		$tag -> setAttribute('type', 'text/javascript');
				
		$this -> vars['scripts'][] = $tag;
	
	}
	
	public function __set($varName, $varValue){
	
		$this -> vars[$varName] = $varValue;
		
	}
	
	public function __get($varName){
	
	
		return $this -> vars[$varName];
		
	
	}
	
	public function exists($varName){
	
		return array_key_exists($varName, $this -> vars);
	
	}
	
	public static function encodeForUrl($iInput){
	
		return preg_replace('/ /','-',$iInput);
	
	}
	
	
	public static function stripHtml($input){
	
		return strip_tags($input);
		
	}
	
	public static function maxChars($string, $chars){
		
		if(strlen($string) > $chars){
		
		return substr($string, 0, $chars) . ' ...';
		}else{
		return substr($string, 0, $chars);
		}
	
	}



}

?>